package com.qiezikaka.kaka.net;

import android.os.Handler;
import android.os.HandlerThread;

import com.qiezikaka.kaka.bean.AllBean;
import com.qiezikaka.kaka.bean.BannerInfo;
import com.qiezikaka.kaka.bean.FuZhuangInfo;
import com.qiezikaka.kaka.bean.HomeCateInfo;
import com.qiezikaka.kaka.bean.HotList;
import com.qiezikaka.kaka.bean.ShopInfo;
import com.qiezikaka.kaka.bean.SiteDetailInfo;
import com.qiezikaka.kaka.bean.SiteSceneShowInfo;
import com.qiezikaka.kaka.bean.UpdataVersionInfo;
import com.qiezikaka.kaka.bean.UploadImgInfo;
import com.qiezikaka.kaka.net.api.ApiService;
import com.qiezikaka.kaka.net.api.CTFactory;
import com.qiezikaka.kaka.net.api.SchedulersCompat;

import java.io.File;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import rx.Observable;

/**
 * Created by Administrator on 2018-04-19.
 * 数据管理类
 */

public class DataManager {

    private ApiService mControlApi;

    private DataManager() {

    }

    public void initService() {
        HandlerThread ioThread = new HandlerThread("IoThread");
        ioThread.start();
        Handler mHandler = new Handler(ioThread.getLooper());
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mControlApi = CTFactory.getControlApi();
            }
        });
    }

    /**
     * 静态内部类的方式,使用单例模式
     */
    public static class DataManagerHolder {
        private final static DataManager INSTANCE = new DataManager();
    }

    /**
     * 公开的方法提供给外部使用
     */
    public static DataManager getInstance() {
        return DataManagerHolder.INSTANCE;
    }

//    //获取banner
    public Observable<BannerInfo> getBannerList() {
        return mControlApi.getBannerList()
                .compose(SchedulersCompat.<BannerInfo>applySchedulers());
    }

    //    //获取banner
    public Observable<HomeCateInfo> getHomeCate() {
        return mControlApi.getHomeCate()
                .compose(SchedulersCompat.<HomeCateInfo>applySchedulers());
    }

    //服装列表
    public Observable<FuZhuangInfo> getFuZhuanList(String cid,String page,String limit,String hot) {
        return mControlApi.getFuZhuanList(cid,page,limit,hot)
                .compose(SchedulersCompat.<FuZhuangInfo>applySchedulers());
    }

    //拍照页详情
    public Observable<SiteDetailInfo> getSiteDetail(String pid) {
        return mControlApi.getSiteDetail(pid)
                .compose(SchedulersCompat.<SiteDetailInfo>applySchedulers());
    }

    //风格详情图
    public Observable<SiteSceneShowInfo> getSiteSceneShow(String id) {
        return mControlApi.getSiteSceneShow(id)
                .compose(SchedulersCompat.<SiteSceneShowInfo>applySchedulers());
    }

    //上传图片文件
    public Observable<UploadImgInfo> onLoadImg(RequestBody pid, MultipartBody.Part thumb) {
        return mControlApi.onLoadImg(pid,thumb)
                .compose(SchedulersCompat.<UploadImgInfo>applySchedulers());
    }

    //检查版本升级
    public Observable<UpdataVersionInfo> getUpdataVersion() {
        return mControlApi.getUpdataVersion()
                .compose(SchedulersCompat.<UpdataVersionInfo>applySchedulers());
    }

    //搜索商家
    public Observable<ShopInfo> getShopInfo(String id) {
        return mControlApi.getShopInfo(id)
                .compose(SchedulersCompat.<ShopInfo>applySchedulers());
    }

  //
    public Observable<AllBean> bindShop(String address, String sid) {
        return mControlApi.bindShop(address,sid)
                .compose(SchedulersCompat.<AllBean>applySchedulers());
    }

    public Observable<AllBean> getIsBind(String address) {
        return mControlApi.getIsBind(address)
                .compose(SchedulersCompat.<AllBean>applySchedulers());
    }


}
